package com.ysh.xiaomi.web.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 袁胜虎 on 2022/8/21 19:16
 */
@WebServlet("/admin")
public class AdminLoginFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        Object admin = ((HttpServletRequest) servletRequest).getSession().getAttribute("admin");
        if (admin==null){
            ((HttpServletResponse)(servletResponse)).sendRedirect("/admin/login.jsp");
            return;
        }
        filterChain.doFilter(servletRequest,servletResponse);
    }

    @Override
    public void destroy() {

    }
}
